RAIS  3.2
C:/Projekte/RAIS/dataaccesslayertest/CommonClasses/FunctionRoleTest.cs
Go to the documentation of this file.
00001 using System;
00002 using System.Collections.Generic;
00003 using System.Text;
00004 using NUnit.Framework;
00005 using RAIS.Common.UserManagement;
00006 using RAIS.DataAccessLayer;
00007 
00008 namespace RAIS.DataAccessLayerTest.CommonClasses
00009 {
00010         [TestFixture]
00011         public class FunctionRoleTest
00012         {
00013                 private int expectedID = 1;
00014                 private string expectedName = "Test FunctionRole";
00015                 private string expectedCategoryName = "Test Category";
00016                 private string expectedSubcategoryName = "Test Subcategory";
00017                 private string expectedMaskName = "Test Mask";
00018                 private FunctionRole.ValidationType expectedValidationType = FunctionRole.ValidationType.DoesNotNeedValidation; 
00019                 private FunctionRoleAttribute expectedFunctionRoleAttribute = new FunctionRoleAttribute();
00020 
00021                 private FunctionRole functionRole;
00022 
00023                 [SetUp]
00024                 public void Init()
00025                 {
00026                         this.expectedFunctionRoleAttribute.Category = new FunctionRole.Category();
00027                         this.expectedFunctionRoleAttribute.Category.Name = this.expectedCategoryName;
00028                         this.expectedFunctionRoleAttribute.Subcategory = new FunctionRole.Subcategory();
00029                         this.expectedFunctionRoleAttribute.Subcategory.Name = this.expectedSubcategoryName;
00030                         this.expectedFunctionRoleAttribute.Mask = new Mask();
00031                         this.expectedFunctionRoleAttribute.Mask.Name = this.expectedMaskName;
00032 
00033                         functionRole = new FunctionRole();
00034                         functionRole.ID = this.expectedID;
00035                         functionRole.Name = this.expectedName;
00036                         functionRole.Attributes.Add(this.expectedFunctionRoleAttribute.ToString(), this.expectedFunctionRoleAttribute);
00037                         functionRole.Validation = this.expectedValidationType;
00038                 }
00039                 [Test]
00040                 public void GetDefaultValidation()
00041                 {
00042                         // Test 
00043                         Assert.AreEqual(FunctionRole.ValidationType.NeedsValidation
00044                                 , FunctionRole.DefaltValidation);
00045                 }
00046                 [Test]
00047                 public void ValidationTypesDictionary_Count()
00048                 {
00049                         // Preparation
00050                         int expectedCount = 3;
00051                         UserManagement userManagement = new UserManagement();
00052 
00053                         // Test 
00054                         Assert.AreEqual(expectedCount, FunctionRole.ValidationTypesDictionary.Count);
00055                 }
00056                 [Test]
00057                 public void ValidationTypesDictionary_NeedsValidation()
00058                 {
00059                         // Preparations
00060                         FunctionRole.ValidationType expectedType = FunctionRole.ValidationType.NeedsValidation;
00061                         int expectedID = 1;
00062                         string expectedVisibleName = "All data changes by this role need validation";
00063                         UserManagement userManagement = new UserManagement();
00064 
00065                         // Test
00066                         FunctionRole.ValidationTypeData validationType = FunctionRole.ValidationTypesDictionary[expectedType];
00067 
00068                         // Checks
00069                         Assert.AreEqual(expectedID, validationType.ID);
00070                         Assert.AreEqual(expectedType, validationType.Type);
00071                         Assert.AreEqual(expectedVisibleName, validationType.VisibleName);
00072                 }
00073                 [Test]
00074                 public void ValidationTypesDictionary_Validates()
00075                 {
00076                         // Preparations
00077                         FunctionRole.ValidationType expectedType = FunctionRole.ValidationType.Validates;
00078                         int expectedID = 2;
00079                         string expectedVisibleName = "This role validates data changes";
00080                         UserManagement userManagement = new UserManagement();
00081 
00082                         // Test
00083                         FunctionRole.ValidationTypeData validationType = FunctionRole.ValidationTypesDictionary[expectedType];
00084 
00085                         // Checks
00086                         Assert.AreEqual(expectedID, validationType.ID);
00087                         Assert.AreEqual(expectedType, validationType.Type);
00088                         Assert.AreEqual(expectedVisibleName, validationType.VisibleName);
00089                 }
00090                 [Test]
00091                 public void ValidationTypesDictionary_DoesNotNeedValidation()
00092                 {
00093                         // Preparations
00094                         FunctionRole.ValidationType expectedType = FunctionRole.ValidationType.DoesNotNeedValidation;
00095                         int expectedID = 3;
00096                         string expectedVisibleName = "This role doesn't need any validation";
00097                         UserManagement userManagement = new UserManagement();
00098 
00099                         // Test
00100                         FunctionRole.ValidationTypeData validationType = FunctionRole.ValidationTypesDictionary[expectedType];
00101 
00102                         // Checks
00103                         Assert.AreEqual(expectedID, validationType.ID);
00104                         Assert.AreEqual(expectedType, validationType.Type);
00105                         Assert.AreEqual(expectedVisibleName, validationType.VisibleName);
00106                 }
00107                 [Test]
00108                 public void GetID()
00109                 {
00110                         // Test 
00111                         Assert.AreEqual(this.expectedID, this.functionRole.ID);
00112                 }
00113                 [Test]
00114                 public void GetName()
00115                 {
00116                         // Test 
00117                         Assert.AreEqual(this.expectedName, this.functionRole.Name);
00118                 }
00119                 [Test]
00120                 public void GetAttributes()
00121                 {
00122                         // Test 
00123                         Assert.AreEqual(this.expectedFunctionRoleAttribute
00124                                 , this.functionRole.Attributes[this.expectedFunctionRoleAttribute.ToString()]);
00125                 }
00126                 [Test]
00127                 public void GetValidation()
00128                 {
00129                         // Test 
00130                         Assert.AreEqual(this.expectedValidationType, this.functionRole.Validation);
00131                 }
00132                 [Test]
00133                 public void GetValidationData()
00134                 {
00135                         // Preparations
00136                         int expectedID = 3;
00137                         FunctionRole.ValidationType expectedType = FunctionRole.ValidationType.DoesNotNeedValidation;
00138                         string expectedVisibleName = "This role doesn't need any validation";
00139                         UserManagement userManagement = new UserManagement();
00140 
00141                         // Test
00142                         FunctionRole.ValidationTypeData validationTypeData = functionRole.ValidationData;
00143 
00144                         // Checks
00145                         Assert.AreEqual(expectedID, validationTypeData.ID);
00146                         Assert.AreEqual(expectedType, validationTypeData.Type);
00147                         Assert.AreEqual(expectedVisibleName, validationTypeData.VisibleName);
00148                 }
00149                 [Test]
00150                 public void SetName()
00151                 {
00152                         // Preparation
00153                         string expectedNewName = "New Test FunctionRole";
00154 
00155                         // Test 
00156                         this.functionRole.Name = expectedNewName;
00157 
00158                         // Check
00159                         Assert.AreEqual(expectedNewName, this.functionRole.Name);
00160                 }
00161                 [Test]
00162                 public void SetValidation()
00163                 {
00164                         // Preparation
00165                         FunctionRole.ValidationType expectedNewValidation = FunctionRole.ValidationType.Validates;
00166 
00167                         // Test 
00168                         this.functionRole.Validation = expectedNewValidation;
00169 
00170                         // Check 
00171                         Assert.AreEqual(expectedNewValidation, this.functionRole.Validation);
00172                 }
00173                 [Test]
00174                 public void ContainsCategoryRestriction()
00175                 {
00176                         bool returnStatus;
00177 
00178                         // Test
00179                         returnStatus = functionRole.ContainsCategoryRestriction(expectedCategoryName);
00180 
00181                         // Check
00182                         Assert.IsTrue(returnStatus, "ContainsCategoryRestriction return status error:");
00183                 }
00184                 [Test]
00185                 public void ContainsSubcategoryRestriction()
00186                 {
00187                         bool returnStatus;
00188 
00189                         // Test
00190                         returnStatus = functionRole.ContainsSubcategoryRestriction(expectedFunctionRoleAttribute.Category, expectedSubcategoryName);
00191 
00192                         // Check
00193                         Assert.IsTrue(returnStatus, "ContainsSubcategoryRestriction return status error:");
00194                 }
00195                 [Test]
00196                 public void ContainsMaskRestriction()
00197                 {
00198                         bool returnStatus;
00199 
00200                         // Test
00201                         returnStatus = functionRole.ContainsMaskRestriction(expectedFunctionRoleAttribute.Category
00202                                 , expectedFunctionRoleAttribute.Subcategory
00203                                 , expectedMaskName);
00204 
00205                         // Check
00206                         Assert.IsTrue(returnStatus, "ContainsMaskRestriction return status error:");
00207                 }
00208                 [Test]
00209                 public void ValidateNewAttribute_AttributeExists()
00210                 {
00211                         bool returnStatus;
00212                         string errorMessage = "";
00213 
00214                         // Test
00215                         returnStatus = functionRole.ValidateNewAttribute(this.expectedFunctionRoleAttribute, ref errorMessage);
00216 
00217                         // Check
00218                         Assert.IsFalse(returnStatus, "ValidateNewAttribute return status error:");
00219                         Assert.AreEqual(RAIS.Common.Messages.FUNCTION_ROLE_ATTRIBUTE_EXISTS, errorMessage);
00220                 }
00221                 [Test]
00222                 public void ValidateNewAttribute_CategoryRestriction()
00223                 {
00224                         bool returnStatus;
00225                         string errorMessage = "";
00226                         FunctionRoleAttribute newFunctionRoleAttribute = new FunctionRoleAttribute();
00227                         newFunctionRoleAttribute.Category = new FunctionRole.Category();
00228                         newFunctionRoleAttribute.Category.Name = RAIS.Common.Constants.ALL_CATEGORIES;
00229                         newFunctionRoleAttribute.Subcategory = new FunctionRole.Subcategory();
00230                         newFunctionRoleAttribute.Subcategory.Name = this.expectedSubcategoryName;
00231                         newFunctionRoleAttribute.Mask = new Mask();
00232                         newFunctionRoleAttribute.Mask.Name = this.expectedMaskName;
00233 
00234                         // Test
00235                         returnStatus = functionRole.ValidateNewAttribute(newFunctionRoleAttribute, ref errorMessage);
00236 
00237                         // Check
00238                         Assert.IsFalse(returnStatus, "ValidateNewAttribute return status error:");
00239                         Assert.AreEqual(RAIS.Common.Messages.FUNCTION_ROLE_ATTRIBUTE_CONFLICT, errorMessage);
00240                 }
00241                 [Test]
00242                 public void ValidateNewAttribute_SubcategoryRestriction()
00243                 {
00244                         bool returnStatus;
00245                         string errorMessage = "";
00246                         FunctionRoleAttribute newFunctionRoleAttribute = new FunctionRoleAttribute();
00247                         newFunctionRoleAttribute.Category = new FunctionRole.Category();
00248                         newFunctionRoleAttribute.Category.Name = this.expectedCategoryName;
00249                         newFunctionRoleAttribute.Subcategory = new FunctionRole.Subcategory();
00250                         newFunctionRoleAttribute.Subcategory.Name = RAIS.Common.Constants.ALL_SUBCATEGORIES;
00251                         newFunctionRoleAttribute.Mask = new Mask();
00252                         newFunctionRoleAttribute.Mask.Name = this.expectedMaskName;
00253 
00254                         // Test
00255                         returnStatus = functionRole.ValidateNewAttribute(newFunctionRoleAttribute, ref errorMessage);
00256 
00257                         // Check
00258                         Assert.IsFalse(returnStatus, "ValidateNewAttribute return status error:");
00259                         Assert.AreEqual(RAIS.Common.Messages.FUNCTION_ROLE_ATTRIBUTE_CONFLICT, errorMessage);
00260                 }
00261                 [Test]
00262                 public void ValidateNewAttribute_MaskRestriction()
00263                 {
00264                         bool returnStatus;
00265                         string errorMessage = "";
00266                         FunctionRoleAttribute newFunctionRoleAttribute = new FunctionRoleAttribute();
00267                         newFunctionRoleAttribute.Category = new FunctionRole.Category();
00268                         newFunctionRoleAttribute.Category.Name = this.expectedCategoryName;
00269                         newFunctionRoleAttribute.Subcategory = new FunctionRole.Subcategory();
00270                         newFunctionRoleAttribute.Subcategory.Name = this.expectedSubcategoryName;
00271                         newFunctionRoleAttribute.Mask = new Mask();
00272                         newFunctionRoleAttribute.Mask.Name = RAIS.Common.Constants.ALL_MASKS;
00273 
00274                         // Test
00275                         returnStatus = functionRole.ValidateNewAttribute(newFunctionRoleAttribute, ref errorMessage);
00276 
00277                         // Check
00278                         Assert.IsFalse(returnStatus, "ValidateNewAttribute return status error:");
00279                         Assert.AreEqual(RAIS.Common.Messages.FUNCTION_ROLE_ATTRIBUTE_CONFLICT, errorMessage);
00280                 }
00281         }
00282 }